@using BlazorDatasheet.Core.Data
@using BlazorDatasheet.Core.Edit
@using BlazorDatasheet.Render
@namespace BlazorDatasheet.Render

@code {

    /// <summary>
    /// A whole Sheet
    /// </summary>
    [CascadingParameter]
    public Sheet Sheet { get; set; }

    /// <summary>
    /// A read-only copy of the cell that this renderer will display.
    /// </summary>
    [Parameter]
    public VisualCell Cell { get; set; }

    /// <summary>
    /// Run when the renderer requests that the cell value is changed (used, for example for the default bool renderer)
    /// </summary>
    [Parameter]
    public Action<ChangeCellValueRequest>? OnChangeCellValueRequest { get; set; }

    /// <summary>
    /// Run when the renderer requests that an edit is started (used, for example for the default select renderer)
    /// </summary>
    [Parameter]
    public Action<CellEditRequest>? OnBeginEditRequest { get; set; }

    /// <summary>
    /// Request that the cell should change value without going to an editor.
    /// </summary>
    /// <param name="value">The value to change the cell to. This will be converted from a string to the appropriate value.</param>
    protected void RequestChangeCellValue(object value)
    {
        OnChangeCellValueRequest?.Invoke(new ChangeCellValueRequest(Cell.Row, Cell.Col, value));
    }

    /// <summary>
    /// Request that the sheet should start editing the cell
    /// </summary>
    /// <param name="isSoftEdit">Whether the edit is a "soft edit"</param>
    /// <param name="mode">The mode used to enter the edit</param>
    protected void RequestEdit(bool isSoftEdit, EditEntryMode mode)
    {
        OnBeginEditRequest?.Invoke(new CellEditRequest(Cell.Row, Cell.Col, isSoftEdit, mode));
    }

}